import { http } from "@/utils/http";

/** 告警联系人模型定义 */
export type AlertPeopleModel = {
  id: number;
  name: string;
  deptId: number;
  phone: string;
  email: string;
  language: string;
  status: number;
  createdAt: string;
  updatedAt: string;
};

/** 分页获取告警联系人列表 */
export const getAlertPeopleListApi = (data: IReqPagerData) => {
  return http.request<Resp<IRespPagerData<AlertPeopleModel>>>(
    "get",
    "/alert-people/page-list",
    { params: data }
  );
};

/** 新增告警联系人 */
export const addAlertPeopleApi = (data: Partial<AlertPeopleModel>) => {
  return http.request<Resp<null>>("post", "/alert-people", { data });
};

/** 更新告警联系人 */
export const updateAlertPeopleApi = (id: number, data: Partial<AlertPeopleModel>) => {
  return http.request<Resp<null>>("put", `/alert-people/${id}`, { data });
};

/** 更新告警联系人状态 */
export const updateAlertPeopleStatusApi = (id: number, status: number) => {
  return http.request<Resp<null>>("patch", `/alert-people/${id}/status`, {
    data: { status }
  });
};

/** 删除告警联系人 */
export const deleteAlertPeopleApi = (id: number) => {
  return http.request<Resp<null>>("delete", `/alert-people/${id}`);
};

/** 根据ID获取告警联系人详情 */
export const getAlertPeopleByIdApi = (id: number) => {
  return http.request<Resp<{
    info: AlertPeopleModel
  }>>('get', '/alert-people/getOne', {
    params: { id }
  });
};

/** 获取告警联系人选项列表 */
export const getAlertPeopleOptionsApi = (params?: { fieldKey?: string; fieldLabel?: string; deptId?:number }) => {
  return http.request<Resp<{
    options: Array<{
      label: string;
      val: string | number;
    }>
  }>>('get', '/alert-people/getOptions', { params });
};
